A comparative study of advanced evolutionary algorithms for optimizing microgrid performance under dynamic pricing conditions

The integration of microgrids into the existing power system framework enhances the reliability and efficiency of the utility grid. This manuscript presents an innovative mathematical paradigm designed for the optimization of both the structural and operational aspects of a grid-connected microgrid, leveraging the principles of Demand-Side Management (DSM). The focus of this work lies in a comprehensive exploration of the implications brought about by the Renewable Generation-Based Dynamic Pricing Demand Response (RGDP-DR) mechanism, particularly in terms of its influence on the optimal microgrid configuration, considering perspectives from end-users and the utility entity. This inquiry is rooted in a holistic assessment that encompasses technical and economic performance benchmarks. The RGDP-induced DR framework adeptly addresses the needs of the consumer base, showcasing notable efficiency and economic feasibility. To address the intricate nonlinear optimization challenge at hand, we employ an evolutionary algorithm named the "Dandelion Algorithm" (DA). A rigorous comparative study is conducted to evaluate the efficacy of four optimization techniques, affirming the supremacy of the proposed DA. Within this discourse, the complexity of microgrid sizing is cast as a dual-objective optimization task. The twin objectives involve minimizing the aggregate annual outlay and reducing emissions. The results of this endeavor unequivocally endorse the superiority of the DA over its counterparts. The DA demonstrates exceptional proficiency in orchestrating the most cost-effective microgrid and consumer invoice, surpassing the performance of alternative optimization methodologies.


List of symbols N S
The number of PV modules F S PV reduction factor P Z L (t) zth Scenario load power (kW) ρ o (i) The initial electricity price ($) P L (i) The initial load demand (kW) E(i, i) Self-elasticity E i, j Cross-elasticity ρ rgdp (i) The RGDP electricity price ($/kWh).P RGDP L (i) The final economic RGDP load model (kWh) e i The orbital eccentricity for the i th planet.R i (t) The Euclidian distance V i (t) The i th planet velocity.ϕ A random number between zero and one.
A number produced based on levy flight.ξ An indicator to reorient the search.h A variable used to regulate how far the Sun is from the planet i.

SOC(t)
Battery state of charge (kWh) The dandelion seed's best position T i The i th planet orbital period The attraction force µ A number produced using random numbers ranging from 0 to 1, levy-flight, and normal distribution.l A linearly decreasing factor from 1.0 to 0.0.δ The likelihood of nutcrackers travelling across the entire search space to look for unreachable locations In contemporary energy landscapes, there has been a noteworthy upswing in the integration of Renewable Energy Sources (RES) with the grid, driven by a commitment to reduce greenhouse gas emissions from conventional fossil fuel-based power plants 1 .This transformative era has witnessed the ascendancy of decentralized RES, strategically positioned to optimize clean energy generation across extensive geographical domains, culminating in the emergence of Microgrid (MG) concepts as compact-scale networks 2 .
Energizing the paradigm of Demand-Side Management (DSM), this paper underscores the imperative for customers to manipulate their energy consumption patterns.The effective application of DSM brings multifaceted benefits, including enhanced system reliability, improved efficiency, reduced microgrid operational costs, optimized load patterns, minimized power outages, decreased carbon emissions, and increased customer satisfaction.Within Demand Response (DR), specifically, load modification strategies, a subset of DSM, various tactics such as strategic load growth, load shifting, valley filling, peak clipping, strategic conservation, and flexible load shaping are employed 3 .These strategies fall into two main approaches: incentive-based and pricebased paradigms 4 .The former encompasses initiatives such as demand buyback/bidding schemes 5 , curtailable / interruptible services 6 , ancillary service programs 7 , emergency DR programs 8 , capacity market programs 9 , and direct load control mechanisms 10 .Conversely, the latter embraces strategies: Time-of-Use (TOU), fixed pricing, real-time pricing, and critical peak pricing models 11 .
In the microgrid planning scope, two pivotal factors-the operator perspective and the client outlook-significantly influence the effectiveness of DSM deployment.From the client's standpoint, electricity bill expenditure is ameliorated, while on the operator's side, DSM engenders a reduction in microgrid overheads and mitigates risks entailed by power deficits 12 .The literature summarizes an array of techniques and mathematical formulations underpinning DSM within MG applications 13 , with a notable exploration into the comparative assessment of diverse Energy Storage Systems (ESS) for DSM through industrial installations detailed in 14 .
In 2020, Renewable Generation-Based Dynamic Pricing (RGDP) DR was proposed in 29 to minimize the total MG cost of an isolated microgrid using MILP.RGDP-DR achieves a zero reduction in energy consumption and maximum customer satisfaction.However, this paper adopts RGDP DR to minimize life cycle emissions and the overall cost of grid-tied MG using the Dandelion Algorithm (DA).
Given the aforementioned investigations, the commonality across prior studies is the trade-off between DRdriven energy reduction and customer satisfaction.This research addresses this gap by introducing a novel DR strategy termed RGDP DR, designed for rescheduling load demands within grid-connected MGs while prioritizing customer satisfaction.To effectively handle this intricate challenge, a novel meta-heuristic approach called the Dandelion Algorithm (DA) is proposed.The primary objective of this algorithm is to determine optimal capacities for distributed energy sources within the microgrid, taking into account the complexities of DSM.A comprehensive comparative analysis is undertaken, comparing the performance of the DA against three alternative optimization methods within the context of grid-connected MGs influenced by the RGDP DR strategy.Through the utilization of MATLAB/M-files simulation software, a mathematical model of the grid-connected MG is established, incorporating the RGDP DR strategy and various optimization techniques.This model serves to demonstrate the effectiveness of the proposed approach in contrast to its counterparts.
Moreover, the modifications introduced in our study are crucial for the specific context of grid-connected microgrids.While the original mathematical model 29 was formulated for an isolated microgrid, we have diligently • Pioneering the integration of a groundbreaking price-based DR paradigm, namely RGDP DR, designed to ensure maximal customer contentment at a reduced operational outlay, within the context of grid-connected MGs.
• Developing an innovative mathematical framework that seamlessly integrates the Demand Response (DR) approach into the optimization challenge of identifying the most efficient dimensions for grid-connected microgrids.This framework aims to achieve two simultaneous goals: the reduction of overall costs and the mitigation of emissions.• Introducing a cutting-edge metaheuristic algorithm, DA, specifically designed to adeptly address the complexities associated with optimizing the size of grid-connected microgrids.The algorithm capitalizes on technical and economic metrics to effectively navigate the inherent intricacies of this optimization problem.
The subsequent sections of the paper are systematically organized as follows: Section "Modeling and configuration of system components" provides a concise explanation of the configuration and modeling complexities related to the proposed grid-connected MG.Section "Problem formulation" presents the formulation of the optimization challenge, incorporating the system's inherent constraints.In Section "RGDP-DR program", a comprehensive depiction of the RGDP DR strategy is provided, along with its intricate modeling.The methodologies underlying the utilization of four distinct optimization techniques to address the optimization problem are concisely summarized in Section "Optimization techniques".Moving forward, Section "Results and discussion" serves as a platform for a thorough examination and discussion of the simulation outcomes across four distinct scenarios.Bringing the discussion to a close, Section "Conclusion" summarizes the cumulative conclusion of this study.

Modeling and configuration of system components
Figure 1 illustrates the arrangement of the proposed MG as described.This MG design incorporates a trio of RES: photovoltaic (PV) panels, battery storage units, and Wind Turbines (WTs).Additionally, a converter is incorporated into the setup to establish a connection between the AC and DC buses.On a specified day, MG registers a peak demand of 2115.4 kW, with a corresponding energy consumption of roughly 21,117.7 kWh.The detailed model for each RES will be discussed in the following subsections:

PV modeling
The PV-generated power P S (t) can be computed using Eq. (1) 30.
where N S is the number of PV modules, P STC is the PV power rating at STC (kW), F S is the PV module reduction factor, and I(t) is the global solar irradiance (W/m 2 ).

WT modeling
WT output power P w (t) can be defined using Eq. (2) 31.
where P r is the WT's rated power, and N w is the number of WTs.

Modeling of the battery energy storage system
Recently, the utilization of lithium-ion batteries has become prevalent in MG applications due to their remarkable characteristics, including high power density, significant energy density, and prolonged lifespan.Battery Energy Storage Systems (BESS) function through three distinct operational modes: charging, discharging, and idle mode.

Charging mode
In instances where the power generated by MG sources exceeds load requirements, the excess power is directed toward charging the battery.Consequently, the methodology outlined below is employed to calculate the accumulated energy from this charging process 32,33 : where P CH (t) is the power being charged at time t , P Z L (t) signifies the load power of the scenario indexed as the zth at time t , and subscript z indicates the specific scenarios under consideration.E CH (t) represents the energy being charged during the time interval t , which is typically an hour.The efficiencies of the converter and charg- ing processes are denoted as η CON and η CH , respectively.
The battery State of Charge ( SOC ) is calculated as: where SOC(t) and SOC(t − 1) are states of charge at two successive time instants of t and t − 1 , respectively.When the calculated P CH (t) is greater than ( SOC max − SOC(t − 1) ), the power can be sold to the connected grid P GS (t) and calculated as: where SOC max refers to the maximum SOC of the battery.

Discharging mode
In cases where the energy demand of a load exceeds the output power of PV and WTs, the battery is discharged.The subsequent energy discharged and the corresponding SOC can be approximated using the following approach 32,33 : where P DIS (t) is battery discharging power at time t , E DIS (t) stands for discharging energy.η DIS is the discharging efficiency.
In the event of a battery power shortage, the purchased grid power P GP (t) can be defined as: where SOC min is the battery minimum permissible SOC.

Ideal mode
Upon reaching full charge, the surplus MG-generated power can be sold back to the grid.This situation is depicted as follows 34 : Once the battery's maximum discharge capacity is reached, any additional power needed will be procured from the grid.This scenario can be articulated as follows: (2)

Problem formulation
This section outlines the technical constraints on the system as well as the optimization problem's objective functions.

The objective functions (OFs)
The study addresses the comprehensive OF inherent in the optimization challenge of microgrid (MG) sizing.The primary objective of this Objective Function (OF) is to simultaneously minimize the Total Annual Cost (TAC) as presented in Eq. ( 12) and reduce Life Cycle Emissions (LCE) as defined in Eq. ( 17) within the context of gridinterconnected MG.The optimization process considers operational constraints delineated in Eqs. ( 18) to (24).Consequently, the overarching objective function is composed of two metrics, each of which is characterized by a specific weight ratio.Therefore, the formulation of the OF is presented as follows: where x represents a vector containing optimization parameters: the power output of sources, storage, and converter.E pen stands for the penalty associated with CO 2 emissions ($/ton).The assigned values for ϕ 1 and ϕ 2 are both set to 0.5.

TAC minimization
It can be calculated as follows 29 : where CC AN , RPC AN , OMC AN , and SVC AN are MG annual capital costs of the MG components, replacement costs, operating and maintenance costs, and salvage costs, respectively.
Components' capital costs.The total yearly MG components' capital cost can be determined using Eq. ( 13) 35 : where N k indicates the number of kth component units, P R_k is the capacity in kW of kth component, C i_k is the kth component initial cost in ($/kW), K is the number of system components,D r indicates the reduction rate (%), T is the project's lifetime, and k indicates the MG components, which are WT, BESS, PV, and converter.
Replacement costs.If the lifetimes of microgrid (MG) components are shorter than the lifespan of the project, they need to be replaced.The overall annual cost of replacing MG components can be calculated using Eq. ( 14) 36 : where NR k indicates the number of kth component replacements, L k is the lifetime in years, and C r_k is the cost of unit replacement ($/kW).
Operating and maintenance O&M costs.Annual O&M costs can be described as 29,30 : where C om_k is the kth component annual O&M costs in $/kW/Year, C gp (t) is the per-unit buying grid power cost at tth hour in $/kW/Year, P gp (t) (kW) is the purchased power from the utility during the tth hour, C gs (t) is the price of the grid sold power in $/kW/Year, and P gs (t) (kW) is the utility sold power.
Salvage costs.The annual MG components' salvage cost can be written as 37 : Minimizing LCE LCE In kilograms of CO 2 -equivalent per year represents the cumulative carbon dioxide (CO 2 ) emissions from microgrid components over their complete lifecycle.This value can be computed using the formula outlined in reference 32 : where F k is the kth component annual CO 2 emissions in kgCO 2 -eq/kWh and E k is the annual generated energy in kWh.MG's detailed characteristics are presented 34 .Operational parameters of MG components must adhere to established limits to ensure the integrity and dependability of the power supply infrastructure.

The technical constraints
Operational parameters of MG components must adhere to established limits to ensure the integrity and dependability of the power supply infrastructure.Inequality and power balance constraints should be calculated and considered, as will be described in the following paragraphs.

The inequality constraints
Maximum and minimum boundaries of MG sources should be satisfied, as follows 34 : where P b (t) is storage power.P S_max , P w_max , and P inv_max are RESs and converter capacities, respectively.P CH_max and P DIS_max represent the maximum battery charging and maximum battery discharging, respectively.
The SOC of the battery must be maintained within the acceptable range, as deep discharges and overcharging can both lead to a reduction in battery lifespan, as explained below 32,33 : At time i , the RGDP electrical cost ρ rgdp (i) must be within the allowable limits as follows 29 : where ρ min and ρ max are the minimum and maximum prices, respectively.

The power balance constraints
Power equilibrium can be achieved through the utilization of the subsequent expression 34 :

RGDP-DR program
An energy management strategy that enables the modification of load patterns is known as DR, where electricity consumption is modified by shifting it from high-demand to low-demand periods or by reducing usage during peak periods.Conventional DR approaches often lead to reduced energy consumption, though they might impact customer satisfaction.On the contrary, the RGDP-DR program distinguishes itself by achieving optimal equilibrium.This program guarantees no reduction in energy consumption, thereby achieving the utmost customer satisfaction, as expounded in this section.
The self-elasticity coefficient E(i, i) refers to the sensitivity of (i) hour demand to (i) hour price and can be expressed using Eq. ( 25) as follows 29 : where ρ o (i) is the initial electrical cost, P L (i) is the initial demand, ∂P L (i) represents the demand variance during period i , and ∂ρ(i) indicates the cost fluctuation during the i period.
The cross-elasticity coefficient E i, j reflects the (i) demand sensitivity to j price and is calculated using Eq. ( 26) as follows 29 : Table 1 shows the applied cross-and self-elasticities of the demand load in this research.RGDP signifies an advanced evolution of time-based Demand Response (DR) programs.This advancement arises from the shift in the DR electricity price, moving from a variable independent of microgrid (MG) configuration to a dynamic value linked to the disparity between energy demand and the Renewable Energy Source (RES) output.Furthermore, RGDP's primary objective is to mitigate customer dissatisfaction while simultaneously enhancing utility for the electricity provider.Consequently, the price structure offered motivates participants to simply reschedule energy usage patterns.As specified in Eq. ( 27), the comprehensive energy consumption of a participant should remain comparatively consistent both before and after the RGDP DR program's implementation 29 .
The RGDP tariff is quantified as follows 29 : The RGDP economic load model is acquired by 29 :

Optimization techniques
Four optimization techniques applied in this paper are mathematically modelled in this section.

PSO algorithm
Eberhart and Kennedy first presented PSO 39 .This algorithm draws inspiration from the flocking behavior of birds aiming to reach a target, with each individual's actions influencing the group's collective movement.In PSO, particles symbolize potential solutions dispersed within the search space to address a given problem.The PSO methodology encompasses five fundamental stages: • Initialization The initial setup of particles and their attributes.
• Evaluation The assessment of each particle's fitness based on the defined objective function.
• Updating Particle Best (Pbest) Individual particles update their personal best solution based on their current fitness.

• Updating Global Best (Gbest)
The best solution among all particles is updated.
• Updating Velocity and Location Particles adjust their velocity and position, guided by both Pbest and Gbest, iteratively moving towards a globally optimal solution.
Particles in PSO emulate the trajectories set by Pbest and Gbest, dynamically altering their directions to progressively converge towards the problem's global optimal solution.

Kepler optimization algorithm (KOA)
KOA draws inspiration from Kepler's planetary motion laws, utilizing them for forecasting the planets' positions and velocities at any specific moment 40 .Within the KOA framework, individual planets, characterized by their respective positions, assume the role of candidate solutions.These planetary positions are iteratively adjusted during the optimization process, referencing the best solution achieved thus far (analogous to the Sun in the solar system).The operational steps of the KOA are visually depicted in the provided flow chart, Fig. 2, illustrating the algorithm's computational procedures and its systematic optimization approach.
According to Fig. 2, KOA can be summarized as follows:

Initialization process
The initial population of planets will be generated randomly within the defined boundaries of the search space, according to Eq. ( 30): ( 27) where X j i represents the i th planet of j th decision variable in the search space.X j i,up and X j i,low denote the maximum and minimum bounds, respectively.
The orbital i th planet eccentricity ( e i ) is initialized using Eq. ( 31): The orbital i th planet period ( T i ) is initialized using Eq. ( 32): where r is a random number produced using the normal distribution.

Defining the Euclidian distance
The Euclidian distance ( R i (t) ) between the Sun X t s,j and a planet X t i,j is defined as: www.nature.com/scientificreports/where d stands for the problem dimension.

Defining the gravitational force
The gravitational force ( F g i (t) ) can be calculated using Eq. ( 34): where M s and m i refer to the normalized mass quantities of the Sun and planet, respectively.ε is a small number.µ is the constant of universal gravity.r 1 is a random number ranging from 0.0 to 1.0.R i is the normalized value of R i .

Calculating planets' velocity
The planet's orbital speed V t i as it orbits the Sun is defined as: where r 3 , r 4 , and r 5 are random numbers ranging from 0.0 to 1.0.X a and X b depict randomly chosen solutions from the population.ξ serves as an indicator to reorient the search.

Updating planets' positions
The new position of each planet is updated using Eq. ( 36): Updating the distance between the planets and the Sun The Sun's distance from each planet is updated using Eq. ( 37): where h is a variable used to regulate how far the Sun is from the planet i.

Elitism
The elitist strategy is described as

Nutcracker optimization algorithm (NOA)
NOA models its behavior after Clark's nutcrackers, delineated by two distinct techniques: the foraging and storage technique and the cache-search and recovery technique 41 .The algorithm's operational processes are graphically outlined in the accompanying flow chart, depicted in Fig. 3.This flow chart offers a visual representation of the sequential steps undertaken by the NOA, aligning with the algorithm's emulation of the nutcrackers' natural behaviors.
NOA is summed up in the following steps:

Initialization process
The NOA population is initialized by where X t i,j indicates the i th nutcracker (feasible solution) of the j th decision variable in generation t .U j and L j denote the j th decision variable maximum and minimum bounds, respectively.RM represents a random vector ranging from 0.0 to 1.0.where γ is a randomly produced number based on the levy flight.A , B , and C are three indicators chosen at random from the population.τ 1 , τ 2 , r , and r 1 are random numbers ranging from 0.0 to 1.0.X t m,j is the average of all solutions in iteration t .µ is a number produced using random numbers ranging from 0 to 1, levy-flight, and normal distribution.δ is the likelihood of nutcrackers travelling across the entire search space to look for unreachable locations.
Storage stage.Nutcrackers start by moving the food acquired in the earlier stage to temporary storage facilities, which can be expressed as follows: where X t+1(new) i denotes a new location in the nutcrackers' storage region in iteration t.X t best indicates the best solution obtained even now.is a number produced based on levy flight.l is a linearly decreasing factor from 1.0 to 0.0.
The interchange between the foraging and storage stages is adopted using Eq. ( 42): where ϕ refers to a random number ranging from 0.0 to 1.0, and P a 1 represents a linearly decreasing probability value from 1.0 to 0.0.

Cache-search and recovery technique
This technique simulates the second behavior of nutcrackers, which involves looking for and retrieving storage spaces during winter and spring.Therefore, this technique can be bifurcated into two principal stages: cache search and recovery.These stages are expounded upon below: Cache-search stage.The nutcrackers start to identify their caches using a spatial memory methodology.For simplicity, NOA supposes that there are just two Reference Points ( RPs ) (objects) per cache.as shown in Eq. (43).
where RP t i,1 and RP t i,2 represent RPs of i th nutcracker cache position in generation t.The RP t i,1 and RP t i,2 are described as follows: where α linearly decreases from one to zero.X t A is the A th nutcracker cache position in iteration t .θ stands for the nutcracker angle of view, which is randomly selected between 0 and π.RP is a random position.
Nutcracker's new position can be updated via RP t i,1 : If the nutcracker is unable to recall where he buried his food utilizing RP t i,1 , RP t i,2 will be used.Therefore, RP t i,2 is used to update Nutcracker spatial memory via Eq.( 47): The exchange between RP t i,1 and RP t i,2 is achieved as follows: Recovery stage.When the nutcracker can recall the cache location using either RP t i,1 or RP t i,2 , there are two outcomes for each: either there is food or there isn't.This process can be expressed as follows: where τ 3 , τ 4 , τ 5 , τ 6 , τ 7 , and τ 8 are random numbers ranging from 0.0 to 1.0.
The interchange between the cache-search and recovery stages is adopted using Eq. ( 50): where P a 2 corresponds to a probability value of 0.2.Nutcracker's current position can be enhanced as follows: (42) Eq.( 40), ϕ > P a 1 Eq.( 41), Otherwise Eq.( 46), f Eq.( 46) < f Eq.( 47) Eq.( 47), Otherwise www.nature.com/scientificreports/Case 1.With increasing wind strength, the dandelion achieves greater height and scatters its seeds over a wider range.This scenario can be mathematically represented as follows: where X t represents the position of the seed at iteration t.X t+1 denotes the seed position at iteration t + 1. X s signifies a random location within the search space.The term lnY represents the logarithmic normal distribution.θ represents a random number falling within the range of [− π, π].T represents the maximum number of iterations.
Case 2. Under rainy conditions, dandelion seeds encounter challenges in achieving optimal ascent against the wind.This situation can be expressed mathematically as follows: Descent phase This phase promotes the exploration process and can be mathematically represented as follows: where β t represents Brownian motion and is a random number drawn from a normal distribution.pop is the population size.

Landing phase
The landing phase facilitates the exploitation process and can be defined by the following equation: where X elite indicates the seed's optimal position during ith iteration.s set at a fixed value of 0.01.w and t are random numbers within the range of [0, 1].β is fixed at 1.5.

Termination
The DA algorithm concludes its execution and provides the optimal solution vector after a certain number of iterations (T).

Results and discussion
The microgrid model proposed in this study is situated in the city of Benban, located within the Aswan Governorate.Geographically, Benban is positioned at a longitude of 32.870°E and a latitude of 24.440°N.Figure 5 displays the consistent fluctuation of wind speed throughout this period, reaching its peak value of 12.4470 m/s at 6 p.m. 43 .This value then gradually diminishes to reach zero by 5 p.m., remaining at this level until 6 a.m. the (53) following day 44 .In contrast, Fig. 6 illustrates a gradual and nonlinear rise in solar irradiance throughout the day, starting from zero at 6 a.m. and peaking at noon with a maximum recorded value of 1187.59W/m 2 .The associated costs for electricity transactions in this microgrid scenario are as follows: purchasing electricity from the utility grid costs 0.20 $/kWh from midnight to 8 a.m., 0.50 $/kWh from 8 a.m. to 4 p.m., and 0.30 $/ kWh from 4 p.m. to midnight, while selling electricity back to the utility is priced at 0.06685 $/kWh 45 .Additionally, Fig. 7 displays the monthly distribution of load demand throughout the year, indicating a peak demand of 2115.40 kW at 5:00 p.m. and a minimum demand of 290.0 kW at 10:00 a.m. 46.The initial price of electricity remains constant at 0.5 $/kWh within each respective period.
To evaluate the effectiveness of the proposed optimization technique, a comparative analysis of performance is conducted.Four distinct operational scenarios (each corresponding to different optimization techniques) are explored for the microgrid model incorporating RGDP DR.This investigation aims to elucidate the impact of the recommended optimization strategy.
Across all scenarios, crucial metrics including energy consumption, decrease in energy consumption, incentives, and penalties result in values of 707,959 kWh, zero, zero, and zero, respectively.The pricing framework encompasses maximum and minimum boundaries set at 0.550 and 0.450 $/kWh, respectively.Figure 8 illustrates the transformation in economic load demand profiles, both before and after the implementation of RGDP DR.Furthermore, the alteration in electricity pricing resulting from RGDP DR is visually presented in Fig. 9, calculated using Eq. ( 28).The results of implementing optimization techniques for obtaining the optimal size of RES for the microgrid will be discussed in the following subsections.

Scenario 1: DA algorithm
The proposed microgrid configuration entails capacities for PV, wind, battery, and converter set at 6579 kW, 937 kW, 3482 kW, and 3212 kW, respectively.These designations align with the life cycle emissions of 2,696,972 kgCO 2 -eq/Year, the total microgrid cost of 1,246,864 $/Year, and the customer bill totaling 3,845,911 $/ Year, as elucidated within Table 2.The hourly output power from each Renewable Energy Source (RES) throughout 24 h is visually illustrated in Fig. 10, employing the Dandelion Algorithm (DA).

Scenario 2: PSO algorithm
The capacities of PV, wind, battery, and converter are 6566 kW, 926 kW, 3523 kW, and 3211 kW, respectively.The life cycle emissions amount to 2,694,292 kgCO 2 -eq/Year, the total microgrid cost is 1,246,866 $/Year, and  the customer bill reaches 3,846,043 $/Year, as detailed in Table 2.The output power of each RES for each hour over a single day is depicted in Fig. 11 through the application of PSO.

Scenario 3: NOA algorithm
The capacities of PV, wind, battery, and converter are 6542 kW, 924 kW, 3537 kW, and 3192 kW, respectively.The life cycle emissions amount to 2,690,314 kgCO 2 -eq/Year, the total microgrid cost is 1,246,871 $/Year, and the customer bill reaches 3,846,108 $/Year, as detailed in Table 2.The output power of each RES for each hour over a single day is illustrated in Fig. 12, utilizing the NOA.The capacities of PV, wind, battery, and converter are 6551 kW, 908 kW, 3617 kW, and 3241 kW, respectively.The life cycle emissions amount to 2,683,489 kgCO 2 -eq/Year, the total microgrid cost is 1,246,905 $/Year, and the customer bill reaches 3,846,235 $/Year, as detailed in Table 2.The output power of each Renewable Energy Source (RES) for each hour over a single day is depicted in Fig. 13 using the KOA.

Conclusion
This paper introduces an innovative methodology for determining the optimal size of a grid-connected microgrid (MG) through an energy management framework with two primary objectives: minimizing the total annual cost and reducing life cycle emissions.The devised microgrid architecture incorporates distributed energy resources such as Battery Energy Storage Systems (BESS), wind turbines (WT), and photovoltaics (PV).A comprehensive mathematical model is presented, integrating the RGDP-DR approach to ascertain the optimal grid-connected MG size.The RGDP DR strategy is devised to address the disparities between demand load and renewable energy source (RES) generation.
The study conducts a thorough comparative analysis involving four optimization techniques: Dandelion Algorithm (DA), Particle Swarm Optimization (PSO), Nature-Inspired Optimization Algorithm (NOA), and Knowledge Optimization Algorithm (KOA).The evaluation metrics encompass life cycle emissions, the optimal microgrid cost, and customer billing.Simulation results demonstrate the superiority of the proposed DA in achieving the lowest microgrid cost and customer bill, outperforming the other optimization methods.Importantly, this evaluation considers only 10% of the load in the management strategy.
DA demonstrates a minimal total annual cost of $1,246,864, leading to a marginal difference compared to other techniques.PSO closely follows, with a total annual cost of $1,246,866, showing comparable performance to DA. NOA and KOA yield similar results, with total annual costs of $1,246,871 and $1,246,905, respectively.In terms of the annual customer bill, DA results in the lowest at $3,845,911, showcasing a distinct advantage over other optimization methods.PSO closely trails DA, with an annual customer bill of $3,846,043, indicating competitive performance.NOA and KOA exhibit comparable annual customer bills, standing at $3,846,108 and $3,846,235, respectively.
In conclusion, this research establishes that the proposed framework offers an optimal approach for developing a sustainable microgrid driven by renewable energy sources.The numerical evidence supports the claim of the Dandelion Algorithm's effectiveness, particularly in minimizing both microgrid cost and customer billing, even when considering only 10% of the load in the management strategy.
In future research, the proposed RGDP-based DR may be employed on interconnected multi-nano grids and microgrids to find the optimal configuration and size of these interconnected microgrids, considering MG configurations, load types, and uncertainties.

Figure 2 .
Figure 2. The flowchart of the KOA algorithm.
X t i,j = U j − L j • RM + L j Vol:.(1234567890)Scientific Reports | (2024) 14:4548 | https://doi.org/10.1038/s41598-024-54829-9www.nature.com/scientificreports/Foraging and storage technique This technique replicates the initial conduct observed in nutcrackers, manifesting during the summer and autumn seasons to gather pine seeds and hoard them.As a result, this technique can be bifurcated into two principal stages: foraging and storage.These stages are expounded upon below: Foraging stage.Every nutcracker starts by examining the cone containing the seeds, as shown in Eq. (40).

Figure 9 .
Figure 9.The generated electricity cost with RGDP DR deployment.

Table 2 .
Overall comparison of the studied scenarios.